import 'package:flutter/material.dart';

///  ***************************************************************************
///  动画加载页面
///  ***************************************************************************

class LoadingDialog extends Dialog {
  String text;

  bool isDismiss = false;

  BuildContext _context;

  LoadingDialog({Key key, @required this.text}) : super(key: key);

  void dismiss(BuildContext context) {
    if (_context == null) {
      return;
    }
    if (!isDismiss) {
      isDismiss = true;
      Navigator.of(_context).pop();
    }
  }

  @override
  Widget build(BuildContext context) {
    if (_context == null) {
      _context = context;
    }
    return GestureDetector(
      onTap: () {
        dismiss(context);
      },
      child: Material(
        //创建透明层
        type: MaterialType.transparency, //透明类型
        child: new Center(
          child: GestureDetector(
            onTap: () {},
            //保证控件居中效果
            child: new SizedBox(
              width: 120.0,
              height: 120.0,
              child: new Container(
                decoration: ShapeDecoration(
                  color: Color(0xffffffff),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8.0),
                    ),
                  ),
                ),
                child: new Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    new CircularProgressIndicator(),
                    new Padding(
                      padding: const EdgeInsets.only(
                        top: 20.0,
                      ),
                      child: new Text(
                        text,
                        style: new TextStyle(fontSize: 12.0),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
